Delphi code for getting/setting print options

The code below assumes that a PrintJob is already open.

Calls used
PEGetPrintOptions
PESetPrintOptions
Code
uses CRDelphi;

var
  wStartPage,
  wStopPage,
  wCopies,     
  wCollation      : Word;
  sOutputFileName : string;

procedure GetPrintOptions;
var
  PrintOpt : PEPrintOptions;
begin
  PrintOpt.StructSize := SizeOf(PEPrintOptions);

  if not PEGetPrintOptions(PrintJob, PrintOpt) then
    {Do Error Handler};

  wStartPage := PrintOpt.StartPageN;
  wStopPage := PrintOpt.StopPageN;
  wCopies := PrintOpt.nReportCopies;
  wCollation := PrintOpt.Collation;
  sOutputFileName := StrPas(@PrintOpt.outputFileName);
end;


{The SetPrintOptions procedure takes a parameter "PromptForOptions" 
which shows how to use the Print Engine to prompt for PrintOptions}
procedure SetPrintOptions(PromptForOptions: boolean);
var
  PrintOpt   : PEPrintOptions;
  pPrintOpt  : ^PEPrintOptions;
  Changed    : boolean;
  sTmp       : string;
begin
  PrintOpt.StructSize := SizeOf(PEPrintOptions);

  pPrintOpt := nil;
  Changed := False;

  if PromptForOptions = True then
  begin
    {By passing in a Nil pointer, the Print Engine will prompt for 
PrintOptions}
    if not PESetPrintOptions(PrintJob, PEPrintOptions(pPrintOpt^)) then
      {Do Error Handler};
    Exit;
  end;

  {Get PrintOptions from Report}
  if not PEGetPrintOptions(PrintJob, PrintOpt) then
    {Do Error Handler};

  {StartPage}
  if PrintOpt.StartPageN <> wStartPage then
  begin
    PrintOpt.StartPageN := wStartPage;
    Changed := True;
  end;

  {StopPage}
  if PrintOpt.StopPageN <> wStopPage then
  begin
    PrintOpt.StopPageN := wStopPage;
    Changed := True;
  end;

  {Copies}
  if PrintOpt.nReportCopies <> wCopies then
  begin
    PrintOpt.nReportCopies := wCopies;
    Changed := True;
  end;

  {Collation}
  if PrintOpt.Collation <> wCollation then
  begin
    PrintOpt.Collation := wCollation;
    Changed := True;
  end;

  {OutputFileName}
  sTmp := StrPas(@PrintOpt.outputFileName);
  if CompareText(sOutputFileName, sTmp) <> 0 then
  begin
    {OutputFileName cannot be larger than 512 characters}
    sTmp := Copy(sOutputFileName, 1, 512);
    StrPCopy(@PrintOpt.outputFileName, sTmp);
    Changed := True;
  end;

  {Send PrintOptions}
  if Changed then
  begin
    if not PESetPrintOptions(PrintJob, PrintOpt) then
      {Do Error Handler};
  end;
end; 


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com